#!/bin/sh

set -e

case "$1" in
  remove)
    if [ -x "/usr/bin/deb-systemd-helper" ]; then
      deb-systemd-helper mask 'netdata.service' >/dev/null || true
      deb-systemd-helper mask 'netdata-updater.timer' >/dev/null || true
    fi
    ;;

  purge)
    if dpkg-statoverride --list | grep -qw /var/cache/netdata; then
      dpkg-statoverride --remove /var/cache/netdata
    fi

    if dpkg-statoverride --list | grep -qw /var/lib/netdata/registry; then
      dpkg-statoverride --remove /var/lib/netdata/registry
    fi

    if dpkg-statoverride --list | grep -qw /var/lib/netdata; then
      dpkg-statoverride --remove /var/lib/netdata
    fi

    if dpkg-statoverride --list | grep -qw /var/run/netdata; then
      dpkg-statoverride --remove /var/run/netdata
    fi

    if dpkg-statoverride --list | grep -qw /var/log/netdata; then
      dpkg-statoverride --remove /var/log/netdata
    fi

    if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper purge 'netdata.service' >/dev/null || true
        deb-systemd-helper unmask 'netdata.service' >/dev/null || true
        deb-systemd-helper purge 'netdata-updater.timer' >/dev/null || true
        deb-systemd-helper unmask 'netdata-updater.timer' >/dev/null || true
    fi

    rm -rf /var/cache/netdata || true
    rm -rf /var/lib/netdata || true
    ;;

  *) ;;

esac

exit 0
